using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Roslyn.Compilers.Common;
using Roslyn.Compilers.CSharp;
using FernUniHagen.CompilerExtension.Interfaces;
using FernUniHagen.CompilerExtension.DataStructures;

namespace FernUniHagen.CompilerExtension.Adaptor
{
    public class ParameterDeclarationAdaptor : DeclarationBase, IDeclaration<CommonSyntaxNode>
    {
        ParameterSyntax _parameterSyntax;


        public ParameterDeclarationAdaptor(ISemanticModel model, ParameterSyntax node) 
        {
            SemanticModel = model;
            _parameterSyntax = node;
            Initialize();
        }

        /// <summary>
        /// Returns the name of the variable
        /// </summary>
        /// <returns></returns>
        public override string GetName()
        {
            return _parameterSyntax.Identifier.ToString() ;
        }

        public override TypeSyntax GetTypeSyntax()
        {
            return _parameterSyntax.Type;
        }

        public override SyntaxList<AttributeListSyntax> GetAttributes()
        {
            return _parameterSyntax.AttributeLists;
        }

        public override StatementReplacement<CommonSyntaxNode> ConvertToMutiplicity(string newVariableName)
        {


            var newIdentifier = Syntax.ParseToken(newVariableName);
            var newParameterSyntax = _parameterSyntax.WithIdentifier(newIdentifier);

            if (MultiplicityType == AttributeType.Any)
            {
                newParameterSyntax = newParameterSyntax.WithType(GenericName);
                return new StatementReplacement<CommonSyntaxNode>(_parameterSyntax, newParameterSyntax);
            }
            return new StatementReplacement<CommonSyntaxNode>(_parameterSyntax, newParameterSyntax);
        }
    }
    
}
